﻿/// <reference path="jquery.min.js" />
jQuery.fn.slideMenu = function(options) {
    var opts = $.extend({}, jQuery.fn.slideMenu.defaults, options);

    return this.each(function() {

        if (opts.width) {
            $("a", $(this)).addClass("ui-state-default").hover(linkMouseEvent, linkMouseEvent)
            .each(function() { $(this).css("width", opts.width) });
        }

        var target = this.nodeName != "UL" ? $(this).find("ul:eq(0)") : $(this);
        target.addClass("slideMenu ui-widget ui-widget-content");

        $("li ul", $("li ul", target))
            .addClass("subMenus")
            .prev().append("<span class='icon ui-icon ui-icon-triangle-1-e'></span>");        
        $(".child").append("<span class='icon ui-icon ui-icon-triangle-1-s'></span>");

        target.children().each(function() {
            $(this).css("float", "left");
            if ($(this).children("ul").length != 0) {
                $("a:eq(0)", this).addClass("child");
            }
        });
        $("li", this).hover(mouseOver, mouseLeave);
    });
};

jQuery.fn.slideMenu.defaults = {
    width: false
};


mouseOver = function(e) {
    var a = $("ul:eq(0)", $(this)).fadeIn('fast');
}

mouseLeave = function(e) {
    $("ul:eq(0)", $(this)).fadeOut('fast');
}

linkMouseEvent = function(e) {
    $(this).toggleClass("ui-state-hover");
}

